﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Reviewer.Entities;
using Reviewer.Entities.Services;
using Reviewer.Business;

public partial class CMSV2_MetaData_GameAccessoriesManager : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            var queryId = Request["Id"] ?? String.Empty;
            int itemId = -1;
            if (queryId.Equals("new"))
            {
                this.uidtItems.Visible = false;
                this.uiPnlEditItem.Visible = true;
                this.uiMiepItem.Reset();

                return;
            }
            else if (int.TryParse(queryId, out itemId) && itemId > 0)
            {
                this.uidtItems.Visible = false;
                this.uiPnlEditItem.Visible = true;
                if (this.uiMiepItem.LoadItem(itemId))
                {
                    return;
                }
            }

            this.uidtItems.Visible = true;
            this.uiPnlEditItem.Visible = false;

            IMetadataService<GameAccessory> dataService = ServiceFactory.GetMetadataService<GameAccessory>();
            this.uidtItems.DataSource = dataService.GetAll();
            this.uidtItems.DataBind();
        }
    }

    protected void uiBtnSave_Click(object sender, EventArgs e)
    {
        if (Page.IsValid)
        {
            this.uiMiepItem.Save();
        }
    }
}